package test08.ts02;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author czl
 * @Date 2024-04-15
 */
public class MainTest06 {
    public static void main(String[] args) {
        // 第一：定义数据源，并获取对应的流对象
        Student s1 = new Student("张三", "男", 18, 55);
        Student s2 = new Student("李四", "女", 28, 63);
        Student s3 = new Student("王五", "男", 38, 50);
        Student s4 = new Student("赵六", "女", 48, 99);
        List<Student> list = Arrays.asList(s1, s2, s3, s4);

        // 第二：操作 - 拼接操作
        // 1.无参:join()
        String str1 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors.joining());
        System.out.println(str1);

        // 2.一个参数:joining(CharSequence delimiter)
        String str2 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors.joining(","));
        System.out.println(str2);

        // 3.三个参数:joining(CharSequence delimiter, CharSequence prefix,CharSequence suffix)
        String str3 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors
                        .joining(",","[","]"));
        System.out.println(str3);

    }
}
